package com.bms.httpModel;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

/**
 * 分页类
 * 
 * @author Lan
 * 
 * @param <T>
 */
public class Pager<T> {

	// 排序方式
	public enum OrderType {
		asc, desc
	}

	public static final Integer MAX_PAGE_SIZE = 500;// 每页最大记录数限制

	private Integer currPage = 1;// 当前页码
	private Integer pageSize = 20;// 每页记录数
	private Integer totalCount = 0;// 总记录数
	private Integer pageCount = 0;// 总页数

	private String orderBy;// 排序字段
	private OrderType orderType = OrderType.desc;// 排序方式
	private List<T> list;// 数据List

	private DetachedCriteria detachedCriteria;

	/**
	 * @return 获取当前页码
	 */
	public Integer getCurrPage() {
		return currPage;
	}

	/**
	 * 前台设置的当前页码
	 * @param currPage
	 */
	public void setCurrPage(Integer currPage) {
		if (currPage < 1)
			currPage = 1;
		this.currPage = currPage;
	}

	/**
	 * @return 每页记录数，默认为20
	 */
	public Integer getPageSize() {
		return pageSize;
	}

	/**
	 * 前台设置的 每页记录数
	 * @param pageSize
	 */
	public void setPageSize(Integer pageSize) {
		if (pageSize < 1) {
			pageSize = 1;
		} else if(pageSize > MAX_PAGE_SIZE) {
			pageSize = MAX_PAGE_SIZE;
		}
		this.pageSize = pageSize;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	/**
	 * 获取总页数（根据总记录数和每页记录数
	 * @return
	 */
	public Integer getPageCount() {
		pageCount = totalCount / pageSize;
		if (totalCount % pageSize > 0) {
			pageCount ++;
		}
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public OrderType getOrderType() {
		return orderType;
	}

	public void setOrderType(OrderType orderType) {
		this.orderType = orderType;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public DetachedCriteria getDetachedCriteria() {
		return detachedCriteria;
	}

	public void setDetachedCriteria(DetachedCriteria detachedCriteria) {
		this.detachedCriteria = detachedCriteria;
	}

}
